package com.wzy.java;

import org.junit.Before;
import org.junit.Test;

import java.util.*;
import java.util.stream.Collectors;

public class test20 {
    private List<String> list = new ArrayList<>();

    List<User> users;

    @Before
    public void load() {
        list.add("张三");
        list.add("李四");
        list.add("王五");
        list.add("赵六");

        users = Arrays.asList(
                new User(1, "张三", 28, 12),
                new User(1, "张三", 29, 11),
                new User(1, "张三", 30, 10),
                new User(1, "张三", 31, 9),
                new User(1, "张三", 32, 8),

                new User(1, "张三1", 33, 7),
                new User(1, "张三1", 35, 5),
                new User(1, "张三1", 36, 4),
                new User(1, "张三1", 37, 3),
                new User(1, "张三1", 38, 2),
                new User(1, "张三1", 39, 1),

                new User(1, "张三2", 34, 6));

    }

    @Test
    public void mapping() {
        Map<Integer, Map<String, Map<Integer, List<Object>>>> collect = users.stream().collect(
                Collectors.groupingBy(User::getId,
                        Collectors.groupingBy(User::getName,
                                Collectors.groupingBy(User::getMonth, Collectors.mapping(item -> {
                                            HashMap<String, User> map1 = new HashMap<>();
                                            map1.put(item.getMonth() + "", item);
                                            return map1;
                                        }, Collectors.toList()
                                )))));

        Integer key = collect.entrySet().iterator().next().getKey();
        Map<String, Map<Integer, List<Object>>> value = collect.entrySet().iterator().next().getValue();

        /*value.forEach((key,value)->{
            
        });*/

        System.out.println(value);


    }
}
